package com.vegetable.modules.controller.finance;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vegetable.common.utils.R;
import com.vegetable.modules.entity.finance.po.ProjectProfitQueryPO;
import com.vegetable.modules.entity.finance.vo.*;
import com.vegetable.modules.service.finance.ProjectProfitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目盈利情况统计控制器
 */
@RestController
@RequestMapping("/project/profit")
@Api(tags = "项目盈利情况统计")
public class ProjectProfitController {

    @Autowired
    private ProjectProfitService projectProfitService;

    /**
     * 项目总体盈利情况
     */
    @GetMapping("/summary")
    @ApiOperation("项目总体盈利情况")
    public R<ProjectProfitSummaryVO> getProjectProfitSummary(ProjectProfitQueryPO po) {
        ProjectProfitSummaryVO summary = projectProfitService.getProjectProfitSummary(po);
        return R.data(summary);
    }

    /**
     * 项目支出明细
     */
    @GetMapping("/expense/details")
    @ApiOperation("项目支出明细")
    public R<IPage<ExpenseDetailVO>> getExpenseDetails(ProjectProfitQueryPO po) {
        IPage<ExpenseDetailVO> page = projectProfitService.getExpenseDetails(po);
        return R.data(page);
    }

    /**
     * 项目收支趋势
     */
    @GetMapping("/trend")
    @ApiOperation("项目收支趋势")
    public R<FinanceTrendVO> getFinanceTrend(ProjectProfitQueryPO po) {
        FinanceTrendVO trend = projectProfitService.getFinanceTrend(po);
        return R.data(trend);
    }

    /**
     * 支出占比分析
     */
    @GetMapping("/expense/ratio")
    @ApiOperation("支出占比分析")
    public R<ExpenseRatioVO> getExpenseRatio(ProjectProfitQueryPO po) {
        ExpenseRatioVO ratio = projectProfitService.getExpenseRatio(po);
        return R.data(ratio);
    }
    
    /**
     * 按商品统计销售情况
     */
    @GetMapping("/sales/commodity")
    @ApiOperation("按商品统计销售情况")
    public R<CommoditySalesPageVO> getSalesByCommodity(ProjectProfitQueryPO po) {
        CommoditySalesPageVO result = projectProfitService.getSalesByCommodityWithTotal(po);
        return R.data(result);
    }
    
    /**
     * 包装类采购统计
     */
    @GetMapping("/purchase/pack")
    @ApiOperation("包装类采购统计")
    public R<PackPurchasePageVO> getPackPurchaseDetails(ProjectProfitQueryPO po) {
        PackPurchasePageVO result = projectProfitService.getPackPurchaseDetailsWithTotal(po);
        return R.data(result);
    }
    
    /**
     * 按客户统计销售及回款数据
     */
    @GetMapping("/sales/customer")
    @ApiOperation("按客户统计销售及回款数据")
    public R<CustomerSalesPageVO> getSalesByCustomer(ProjectProfitQueryPO po) {
        CustomerSalesPageVO result = projectProfitService.getSalesByCustomerWithTotal(po);
        return R.data(result);
    }
    
    /**
     * 加工订单损耗情况统计
     */
    @GetMapping("/pack/loss")
    @ApiOperation("加工订单损耗情况统计")
    public R<PackLossPageVO> getPackLossDetails(ProjectProfitQueryPO po) {
        PackLossPageVO result = projectProfitService.getPackLossDetails(po);
        return R.data(result);
    }
}